home *** CD-ROM | disk | FTP | other *** search
- /* checkdisk.c */
-
- #include "devices/trackdisk.h"
-
- #define BLOCKSIZE TD_SECTOR
- #define TRACKSIZE TD_SECTOR * NUMSECS
- #define MEMF_CHIP (1L<<1)
-
- unsigned char *diskbuffer;
- long td_open_error = -1;
-
- struct MsgPort *diskport;
- struct IOExtTD *diskreq;
-
- extern struct MsgPort *CreatePort();
- extern struct IORequest *CreateExtIO();
-
- void MotorOnOff(onoff) /* TURN DISK MOTOR ON/OFF */
- long onoff;
- {
- diskreq->iotd_Req.io_Length = onoff;
- diskreq->iotd_Req.io_Command = TD_MOTOR;
- DoIO(diskreq);
- }
-
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- long unit, offset;
-
- if (argc>1)
- {
- unit = atoi(argv[1]);
- if( unit < 0 || unit > 3) exit(0);
- }
- else
- unit = 1;
-
- if((diskbuffer = AllocMem(TRACKSIZE,MEMF_CHIP))==0) cleanup();
-
- if((diskport = CreatePort(0,0)) == 0) cleanup();
- /* make an io request block for communicating with the disk */
- if((diskreq = (struct IOExtTD *)CreateExtIO(diskport, sizeof(struct IOExtTD)))== 0)
- cleanup();
-
- if(td_open_error = OpenDevice(TD_NAME,unit,diskreq,0)) cleanup();
-
- MotorOnOff(1); /* Motor On */
-
- for(offset=0;offset<TRACKSIZE*NUMCYLS*NUMHEADS;offset+=TRACKSIZE)
- {
- diskreq->iotd_Req.io_Flags = 0;
- diskreq->iotd_Req.io_Length = TRACKSIZE;
- diskreq->iotd_Req.io_Data = (APTR)diskbuffer;
- diskreq->iotd_Req.io_Offset = offset; /* type long */
- diskreq->iotd_Req.io_Command = ETD_READ;
- /* check that disk not changed before reading */
- diskreq->iotd_Count = 0xFFFFFFFF;
- diskreq->iotd_SecLabel = 0;
-
- DoIO(diskreq);
-
- if(diskreq->iotd_Req.io_Error != 0)
- printf("\nError %ld at Cylinder %ld, Head %ld.",
- diskreq->iotd_Req.io_Error,
- offset/(NUMHEADS*TRACKSIZE),
- offset/(NUMCYLS*TRACKSIZE) );
- }
- MotorOnOff(0);
-
- cleanup();
- } /* end of main */
-
- cleanup()
- {
- if(diskbuffer) FreeMem(diskbuffer,BLOCKSIZE);
- if(!td_open_error) CloseDevice(diskreq);
- if(diskreq) DeleteExtIO(diskreq, sizeof(struct IOExtTD));
- if(diskport) DeletePort(diskport);
- exit(0);
- }
-
-